﻿@using HPIT.RentHouse.DTO
@model RoleEditDTO
@{
    Layout = "~/Views/Shared/_Layout1.cshtml";
    ViewBag.Title = "Create";
}
<div class="cl pd-20">
    <form action="@Url.Action("UpdateRole","Roles")" method="post" class="form form-horizontal" id="form-edit">
        @Html.HiddenFor(Model => Model.Id)
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.Name" placeholder="" id="user-name" name="Name" datatype="*2-16" nullmsg="用户账户不能为空">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色权限：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <dl class="permission-list">
                    <dt><label>选择权限</label></dt>
                    <dd>
                        <dl class="cl permission-list2">
                            @foreach (PermissionDTO permission in ViewBag.perList)
                            {
                                bool isChecked = false;
                                if (Model.PermissionIds!=null&&Model.PermissionIds.Contains(permission.Id))
                                {
                                    isChecked = true;
                                }
                                <dt>
                                    <label class="">
                                        <input type="checkbox" name="PermissionIds" value="@permission.Id" checked="@isChecked">
                                        @permission.Description
                                    </label>
                                </dt>
                            }
                        </dl>
                    </dd>
                </dl>
            </div>
        </div>
        <div class="row cl">
            <div class="col-10 col-offset-2">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>

    </form>
</div>
@section footScript{
    <script>
        $(function () {

            $("#form-edit").validate({
                rules: {
                    Name: {
                        required: true,
                        maxlength: 50
                    }
                },

                messages: {
                    Name: {
                        required: "不能为空"
                    }
                },

                //提交表单
                submitHandler: function (form) {
                    //使用ajax方式提交表单
                    $(form).ajaxSubmit({
                        success: function (data) {
                            console.log(data)
                            //State=1成功，-1失败
                            if (data.State == 1) {
                                //刷新页面
                                parent.location.reload();
                            } else {
                                layer.msg(data.ErrorMessage, { icon: 2 });
                            }
                        }
                    });
                }
            });
        });
    </script>
}

